package design.mode.model.composite;

/**
 * @description 菜单组件，属于抽象根节点
 * @since jdk11
 */
public abstract class MenuComponent {
    protected String id;
    protected String parentId;
    protected String url;
    protected boolean effective;
    /**
     * 菜单组件名称
     */
    protected String name;
    /**
     * 菜单组件层级
     */
    protected int level;



    /**
     * 添加子菜单
     *
     * @param menuComponent 菜单项或菜单项
     */
    public void add(MenuComponent menuComponent) {
        throw new UnsupportedOperationException("菜单项下不能再有子菜单");
    }

    /**
     * 移除子菜单
     *
     * @param menuComponent 菜单项或菜单项
     */
    public void remove(MenuComponent menuComponent) {

    }

    /**
     * 获取指定的菜单
     *
     * @param index 菜单索引
     */
    public MenuComponent getChild(int index) {
        throw new UnsupportedOperationException("菜单项下不能再有子菜单");
    }


    /**
     * 打印菜单名称(包含子菜单和菜单项)
     */
    public abstract void print();

    @Override
    public String toString() {
        return "MenuComponent{" +
                "id='" + id + '\'' +
                ", parentId='" + parentId + '\'' +
                ", url='" + url + '\'' +
                ", effective=" + effective +
                ", name='" + name + '\'' +
                ", level=" + level +
                '}';
    }

}
